{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1ede8c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import h5py\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.image as mpimg\n",
    "import os\n",
    "import os.path as osp\n",
    "import imageio.v2 as imageio\n",
    "\n",
    "from scipy.stats import describe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "adc498a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "s = 0\n",
    "# List of file paths\n",
    "root = \"/lc/data/3D/infinigen/2e962781/frames/Image/camera_0\"\n",
    "file_paths = sorted([f for f in os.listdir(root) if f.endswith(\".png\")])\n",
    "\n",
    "cols = 2\n",
    "rows = 5\n",
    "interval = 1\n",
    "# Create a figure with 2 columns and 10 rows,dpi=100\n",
    "fig, axs = plt.subplots(rows, cols, figsize=(12, rows*3))\n",
    "\n",
    "# Iterate over the file paths and display the images\n",
    "for i, file_path in enumerate(file_paths[s:rows*cols*interval//2+s:interval]):\n",
    "    img_f = osp.join(root, file_path)\n",
    "    img = mpimg.imread(img_f)\n",
    "    depth_f = img_f.replace(\"Image\",\"Depth\").replace(\".png\",\".npy\")\n",
    "    depth = np.load(depth_f)\n",
    "    depth_v = depth[np.isfinite(depth)]\n",
    "    desc = f'{depth_v.min()}, {depth_v.max()}, {depth_v.mean()}'\n",
    "    axs[i * 2 // cols , i * 2 % cols ].imshow(img)\n",
    "    axs[i * 2 // cols , i * 2 % cols].axis(\"off\")  # Hide axis ticks\n",
    "    axs[i * 2 // cols , i * 2 % cols].set_title(file_path.split('_')[3]+f\"_{i}\")\n",
    "    axs[i * 2 // cols , i * 2 % cols + 1].imshow(depth)\n",
    "    axs[i * 2 // cols , i * 2 % cols + 1].axis(\"off\")  # Hide axis ticks\n",
    "    axs[i * 2 // cols , i * 2 % cols + 1].set_title(desc)\n",
    "\n",
    "plt.show()\n",
    "# continious pose with small motion\n",
    "# skip 10 images still overlaps much"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e6d3162",
   "metadata": {},
   "outputs": [],
   "source": [
    "file_path = file_paths[0]\n",
    "img_f = osp.join(root, file_path)\n",
    "img = mpimg.imread(img_f)\n",
    "print(img.shape)\n",
    "cam_f = img_f.replace(\"Image\",\"camview\").replace(\".png\",\".npz\")\n",
    "cam = np.load(cam_f)\n",
    "# print(type(cam), cam.keys())\n",
    "print(\"K\", cam['K'])\n",
    "print(\"T\", cam['T'])\n",
    "print(\"HW\", cam['HW'])\n",
    "# (720, 1280, 3) need resize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd801228",
   "metadata": {},
   "outputs": [],
   "source": [
    "depth_f = img_f.replace(\"Image\",\"Depth\").replace(\".png\",\".npy\")\n",
    "depth = np.load(depth_f)\n",
    "print(depth.shape) \n",
    "print(describe(depth, axis=None))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "vggt",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
